{extend name="index/base" /}
{block name="content"}
<blockquote class="layui-elem-quote fhui-admin-main_hd">
    <h2>加密解密测试</h2>
</blockquote>

<div class="y-role">
    <!--文字列表-->
    <div class="fhui-admin-table-container">
        <form class="layui-form" lay-filter="form1">
            <div class="layui-form-item">
                <label class="layui-form-label">明文</label>
                <div class="layui-input-block">
                    <textarea name="text" id="text" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">操作</label>
                <div class="layui-input-block">
                    <a href="javascript:;" class="layui-btn" id="encryptBtn">加密</a>
                    <a href="javascript:;" class="layui-btn" id="decryptBtn">解密</a>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密文</label>
                <div class="layui-input-block">
                    <textarea name="encrypt" id="encrypt" class="layui-textarea"></textarea>
                </div>
            </div>
        </form>
    </div>
</div>

{/block}
{block name="js"}

<script type="text/javascript">
    layui.use(['table', 'jquery', 'form'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.$;
        $('#encryptBtn').click(function(){
            var text = $('#text').val();
            var load = layer.load(1);
            $.post('{:url("aesTest")}',{type:'encrypt',text:text},function(res){
                if(res.code==0) {
                    $('#encrypt').val(res.data);
                } else {
                    layer.msg(res.msg,{time:1000,icon:2});
                }
                layer.close(load);
            })
        });

        $('#decryptBtn').click(function(){
            var text = $('#encrypt').val();
            var load = layer.load(1);
            $.post('{:url("aesTest")}',{type:'decrypt',text:text},function(res){
                if(res.code==0) {
                    $('#text').val(res.data);
                } else {
                    layer.msg(res.msg,{time:1000,icon:2});
                }
                layer.close(load);
            })
        })
    });
</script>
{/block}